import request from './axios'

/**
 * 疾病管理API接口
 */
const diseaseApi = {
  /**
   * 获取所有疾病列表
   * @returns {Promise}
   */
  getAll: () => {
    return request.get('/api/diseases')
  },

  /**
   * 根据ID获取疾病信息
   * @param {Number} id - 疾病ID
   * @returns {Promise}
   */
  getById: (id) => {
    return request.get(`/api/diseases/${id}`)
  },

  /**
   * 根据条件查询疾病
   * @param {Object} params - 查询条件
   * @returns {Promise}
   */
  getByCondition: (params) => {
    return request.post('/api/diseases/condition', params)
  },

  /**
   * 分页查询疾病
   * @param {Object} params - 分页参数
   * @returns {Promise}
   */
  getByPage: (params = {}) => {
    const { page = 1, size = 10 } = params
    return request.get('/api/diseases/page', {
      params: {
        page,
        size
      }
    })
  },

  /**
   * 条件分页查询疾病
   * @param {Object} params - 查询参数
   * @returns {Promise}
   */
  getByConditionAndPage: (params = {}) => {
    const { page = 1, size = 10, condition = {} } = params
    return request.post('/api/diseases/page/condition', condition, {
      params: {
        page,
        size
      }
    })
  },

  /**
   * 添加疾病
   * @param {Object} data - 疾病数据
   * @returns {Promise}
   */
  add: (data) => {
    return request.post('/api/diseases', data)
  },

  /**
   * 批量添加疾病
   * @param {Array} data - 疾病列表
   * @returns {Promise}
   */
  addBatch: (data) => {
    return request.post('/api/diseases/batch', data)
  },

  /**
   * 更新疾病
   * @param {Number} id - 疾病ID
   * @param {Object} data - 更新的疾病数据
   * @returns {Promise}
   */
  update: (id, data) => {
    return request.put(`/api/diseases/${id}`, data)
  },

  /**
   * 删除疾病
   * @param {Number} id - 疾病ID
   * @returns {Promise}
   */
  delete: (id) => {
    return request.delete(`/api/diseases/${id}`)
  },

  /**
   * 批量删除疾病
   * @param {Array} ids - 疾病ID列表
   * @returns {Promise}
   */
  deleteBatch: (ids) => {
    return request.delete('/api/diseases/batch', {
      data: ids
    })
  }
}

export default diseaseApi